package cn.itcast.controller;

import cn.itcast.domain.Student;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/stu/*")
public class StudentServlet extends BaseServlet {
    //分页查询
    private void selectByPage(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("哈哈哈哈哈哈哈");

        //获取页面参数
        String currentPage = req.getParameter("currentPage");
        String pageSize = req.getParameter("pageSize");
        //System.out.println(currentPage+":::::::::"+pageSize);
        //调用service方法查询
        Page page =  studentService.selectByPage(Integer.parseInt(currentPage),Integer.parseInt(pageSize));
        //封装pageinfo
        PageInfo info = new PageInfo(page);
        System.out.println(info);

      //  System.out.println(info.getList()   );


        //转成json响应给前端q
        ObjectMapper om = new ObjectMapper();
        String json = om.writeValueAsString(info);
        resp.getWriter().write(json);
        System.out.println(json);

    }
}
